<?php

use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class ChapterVodSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'ChapterSeeder',
            'UserSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $chapters = $this->fetchAll("SELECT * FROM kg_chapter");

        $rows = [];
        foreach ($chapters as $chapter) {
            $vods = [
                [
                    'url' => 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4',
                    'width' => 640,
                    'height' => 360,
                    'definition' => 100210,
                    'duration' => 60,
                    'format' => 'mp4',
                    'size' => "4.37",
                    'rate' => 456,
                ],
                [
                    'url' => 'https://www.w3schools.com/html/movie.mp4',
                    'width' => 320,
                    'height' => 240,
                    'definition' => 100220,
                    'duration' => 12,
                    'format' => 'mp4',
                    'size' => "4.37",
                    'rate' => 456,
                ],
            ];
            $rows[] = [
                'course_id' => $chapter['course_id'],
                'chapter_id' => $chapter['id'],
                'file_id' => $faker->iban(),
                'file_transcode' => json_encode($vods, JSON_UNESCAPED_UNICODE),
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }

        $this->table('kg_chapter_vod')->insert($rows)->saveData();
    }

}
